//
//  FreeManagerSelfViewModel.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/8.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "FreeManagerSelfViewModel.h"
#import "FreeManagerSelfOneTableViewCell.h"
#import "FreeManagerSelfTwoTableViewCell.h"
#import "FreeManagerSelfThreeTableViewCell.h"
#import "FreeManagerSelfFiveTableViewCell.h"
#import "FreeManagerSelfFoutTableViewCell.h"

@interface FreeManagerSelfViewModel ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *selfTableView;
}
@end

@implementation FreeManagerSelfViewModel
- (instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView
{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        CGFloat t_height;
        if (iPhoneX) {
            t_height = kHeightProportion_In_iPhoneTriploid(11) + 83;
        } else {
            t_height = kHeightProportion_In_iPhoneTriploid(44) + 49;
        }
        tableView.height = tableView.height - t_height;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        tableView.sectionFooterHeight = 0.0;
        tableView.sectionHeaderHeight = 0.0;
        selfTableView = tableView;
        [superView addSubview:tableView];
    }
    return self;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return kHeightProportion_In_iPhoneTriploid(10);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}

#pragma mark - tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BaseTableViewCell *cell;
    kWeakSelf(self);
    
    switch (indexPath.section) {
        case 0: {
            FreeManagerSelfOneTableViewCell *decell = [FreeManagerSelfOneTableViewCell cellWithTableView:tableView];
            decell.BlockInto = ^(GLGWButton *btn) {
                [weakself rightAction:btn];
            };
            cell = decell;
        }
            break;
        case 1: {
            FreeManagerSelfTwoTableViewCell *decell = [FreeManagerSelfTwoTableViewCell cellWithTableView:tableView];
            cell = decell;
        }
            break;
        case 2: {
            FreeManagerSelfThreeTableViewCell *decell = [FreeManagerSelfThreeTableViewCell cellWithTableView:tableView];
            decell.BlockLeft = ^(GLGWButton *btn) {
                [weakself leftAction:btn];
            };
            cell = decell;
        }
            break;
        case 3: {
            FreeManagerSelfFoutTableViewCell *decell = [FreeManagerSelfFoutTableViewCell cellWithTableView:tableView];
            cell = decell;
        }
            break;
        case 4: {
            FreeManagerSelfFiveTableViewCell *decell = [FreeManagerSelfFiveTableViewCell cellWithTableView:tableView];
            cell = decell;
        }
            break;
        default:
            break;
    }
    return cell;
}

- (void)rightAction:(GLGWButton *)sender
{
    if (self.BlockInto) {
        self.BlockInto(sender);
    }
}

- (void)leftAction:(GLGWButton *)sender
{
    if (self.BlockLeft) {
        self.BlockLeft(sender);
    }
}

@end
